{template "header.html", "/"}
<?php
$comment = dr_comment(SITE_ID.'_'.MOD_DIR, $id);
$comment_table = SITE_ID.'_'.MOD_DIR.'_comment_data_'.$comment['tableid'];
$comment_url = dr_url(MOD_DIR.'/comment/add', array('id' => $id));
$last_page_url = $url;
?>

<div class="page-container">
    <div class="page-content-wrapper">
        {template "header.html"}
        <div class="page-content">
            <div class="container">

                <ul class="page-breadcrumb breadcrumb">
                    <li>
                        <a href="{SITE_URL}">首页</a>
                        <i class="fa fa-circle"></i>
                    </li>

                    {if !IS_SHARE}
                    <li>
                        <a href="{MODULE_URL}">{MODULE_NAME}</a>
                        <i class="fa fa-circle"></i>
                    </li>
                    {/if}
                    {dr_catpos($catid, '', true, '<li><a href="{url}">{name}</a><i class="fa fa-circle"></i></li>')}
                    <li>
                        <a href="{$url}">{$title}</a>
                    </li>
                </ul>

                <div class="page-content-inner">
                    {if $page==1}
                    <div class="search-page search-content-2 portlet light">
                        <div class="row">
                            <div class="col-md-2 text-center wbbs_avatar">
                                {php $user=dr_member_info($uid);}
                                <p class="wbbs_avatar_url"><img src="{$user.avatar_url}"></p>
                                <p>{$user.username}</p>
                                <p >{$user.groupname}</p>
                            </div>
                            <div class="col-md-10 wbbs_show">
                                <div class="portlet light">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <span class="caption-subject font-dark bold" {if $color}style="color:{$color} !important"{/if}>{$title}</span>
                                        </div>
                                        <div class="actions">
                                            <a class="btn btn-circle btn-icon-only btn-default fullscreen" href="javascript:;" data-original-title="" title="全屏查看"> </a>
                                        </div>
                                    </div>
                                    <div class="search-post-foot" style="padding-top:0px;text-align:left;padding-bottom: 10px">
                                        <div class="search-post-meta">
                                            <i class="icon-user font-blue"></i>
                                            <a href="javascript:;">{$author}</a>
                                        </div>
                                        <div class="search-post-meta">
                                            <i class="icon-calendar font-blue"></i>
                                            <a href="javascript:;">{$inputtime}</a>
                                        </div>
                                        <div class="search-post-meta">
                                            <i class="icon-fire font-blue"></i>
                                            <a href="javascript:;">{dr_show_hits($id)}次</a>
                                        </div>
                                        <div class="search-post-meta">
                                            <i class="icon-bubble font-blue"></i>
                                            <a href="javascript:;">{$comments}</a>
                                        </div>
                                        <div class="search-post-meta">
                                            <i class="icon-flag font-blue"></i>
                                            <a href="javascript:dr_favorite();">加入收藏</a>
                                        </div>
                                    </div>
                                    <div class="portlet-body" style="height: auto;">
                                        {$content}
                                    </div>
                                </div>
                                <div class="wbbs_reply">
                                    <a href="javascript:dr_reply_comment(0);" class=""><i class="fa fa-plus-square"></i> 回帖</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {/if}

                    {if $comment}
                    {list action=table table=$comment_table cid=$id status=1 order=inputtime_asc page=1 pagesize=10 urlrule=$urlrule cache=10}
                    <div class="search-page search-content-2 portlet light">
                        <div class="row">
                            <div class="col-md-2 text-center wbbs_avatar">
                                {php $user=dr_member_info($t.uid);}
                                <p class="wbbs_avatar_url"><img src="{$user.avatar_url}"></p>
                                <p>{$user.username}</p>
                                <p >{$user.groupname}</p>
                            </div>
                            <input type="hidden" id="dr_comment_{$t.id}" value="{php echo $user ? $user.username : 'undefined';}">
                            <input type="hidden" id="dr_blockquote_{$t.id}" value="{dr_strcut(dr_clearhtml($t.content), 100)}">
                            <div class="col-md-10 wbbs_show">
                                <div class="portlet light">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <span class="caption-subject font-dark" style="font-size: 12px">
                                                第{$page+$key}楼
                                                回复于: {dr_fdate($t.inputtime)}
                                            </span>
                                        </div>
                                    </div>

                                    <div class="portlet-body" style="height: auto;">
                                        {$t.content}
                                    </div>
                                </div>

                                <div class="wbbs_reply">
                                    <a href="javascript:dr_reply_comment({$t.id});" class=""><i class="fa fa-plus-square"></i> 回帖</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    {/list}
                    <?php $last_page_url = str_replace('{page}', ceil($total/$pagesize), $urlrule); ?>
                    {/if}

                    {if $pages}
                    <div class="search-page search-content-2 portlet light">
                        <div class="row">
                            <div class="col-md-12 text-center wbbs_avatar">
                                <div class="search-pagination text-center">
                                    <ul class="pagination">
                                        {$pages}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    {/if}

                    <div class="search-page search-content-2 portlet light">
                        <div class="row">
                            <div class="col-md-2 text-center wbbs_avatar">
                                <p class="wbbs_avatar_url"><img src="{$member.avatar_url}"></p>
                                <p>{$member.username}</p>
                                <p >{$member.groupname}</p>
                            </div>
                            <div class="col-md-10 wbbs_show">
                                <div class="portlet light">
                                    <div class="portlet-body" style="height: auto;">


                                        <form action="" id="myform" method="post" class="form-horizontal" novalidate>
                                            <div class="form-body">

                                                <div class="form-group">
                                                    <div class="col-md-12">
                                                        <script type="text/javascript">var DR_DIV2P = true;</script>
                                                        <script type="text/javascript" src="/api/ueditor/ueditor.config.js"></script>
                                                        <script type="text/javascript" src="/api/ueditor/ueditor.all.js"></script>
                                                        <script type="text/javascript" src="/api/ueditor/lang/zh-cn/zh-cn.js"></script>
                                                        {php $ci->load->helper(array('system'));}
                                                        {dr_field_input('content', 'Ueditor', array('option' => array( 'mode' => 3, 'height' => 220, 'width' => '100%', 'tool' => '\'simpleupload\', \'attachment\', \'insertimage\', \'insertcode\''), 'validate' => array('xss' => 1)))}
                                                    </div>
                                                </div>
                                            </div>
                                            {if $ci->get_cache('comment', 'comment-module-'.MOD_DIR, 'value', 'permission', $markrule, 'code')}
                                            <div class="form-group" id="dr_row_code">
                                                <div class="col-md-4">
                                                    <label>
                                                        <div class="form-recaptcha">
                                                            <div class="input-group">
                                                                <input type="text" id="dr_code" class="form-control" name="code">
                                                                <div class="input-group-btn fc-code">
                                                                    {dr_code(120, 35)}
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </label>
                                                </div>
                                            </div>
                                            {/if}

                                            <div class="form-actions">
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <button class="mysubmit btn green" type="button" onclick="dr_post_comment()"><i class="fa fa-save"></i> 回复</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>


                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script language="javascript">
    // 这是加入收藏夹的ajax请求，我就随意写了一下提示信息，至于美化啊什么交给你们了
    function dr_favorite() {
        $.get("/index.php?s={MOD_DIR}&c=api&m=favorite&id={$id}", function(data){
            if (data == 1) {
                dr_tips("没有登录，不能收藏");
            } else if (data == 2) {
                dr_tips("文档不存在，无法收藏");
            } else if (data == 3) {
                dr_tips("更新收藏成功", 3, 1);
            } else if (data == 4) {
                dr_tips("收藏成功", 3, 1);
            }
        });
    }
    // 评论提交
    function dr_post_comment() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{$comment_url}",
            data: $("#myform").serialize(),
            success: function(data) {
                if (data.status == 1) {
                    dr_tips(data.code, 3, 1);
                    // 刷新页面
                    window.setTimeout("window.location.href='{$last_page_url}'", 2000);
                } else {
                    dr_tips(data.code)
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {}
        })
    }
    function dr_reply_comment(id) {
        var valc =  $.trim($('#dr_comment_'+id).val());
        if (valc =='' || valc == undefined || valc == 'undefined') {
            // 不管
        } else {
            var html = '@'+valc;
            html+= '<blockquote>'+$('#dr_blockquote_'+id).val()+'</blockquote>';
            html+= '<p></p><br>';
            UE.getEditor('dr_content').setContent( html + '  '+ UE.getEditor('dr_content').getContent() );
        }
        $('html,body').animate({scrollTop:$('#myform').offset().top}, 800);
    }
</script>

{template "footer.html", "/"}